package 排序;

import 排序.交换排序.QuickSort;
import 排序.交换排序.bubbleSort;
import 排序.插入排序.Direct_insertion_sort;
import 排序.插入排序.Shell_sort;
import 排序.选择排序.HeapSort;
import 排序.选择排序.SelectSort;

import java.util.Arrays;
import java.util.Random;

public class Main {

    public static void inorderArray(int[] array){
        for(int i=0;i<array.length;i++){
            array[i]=i+1;
        }
    }

    public static void notInorderArray(int[] array){
        for(int i=0;i<array.length;i++){
            array[i]=array.length-i;
        }
    }

    public static void initArray(int[] array){
        Random random = new Random();
        for(int i=0;i<array.length;i++){
            array[i]=random.nextInt(array.length);
        }
    }

    public static void textInsertSort(int[] array){
        //直接插入排序
        int[] newArray=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();

        Direct_insertion_sort.InsertSort(newArray);

        long endTime=System.currentTimeMillis();
        System.out.println("直接插入排序："+(endTime-startTime));
    }
    public static void textShellSort(int[] array){
        //希尔排序
        int[] newArray=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();

        Shell_sort.ShellSort(newArray);

        long endTime=System.currentTimeMillis();
        System.out.println("希尔排序："+(endTime-startTime));
    }

    public static void textSelectSort(int[] array){
        //排序.选择排序
        int[] newArray=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();

        SelectSort.selectSort(newArray);

        long endTime=System.currentTimeMillis();
        System.out.println("排序.选择排序："+(endTime-startTime));
    }

    public static void textSelectSort2(int[] array){
        //排序.选择排序
        int[] newArray=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();

        SelectSort.SelectSort2(newArray);

        long endTime=System.currentTimeMillis();
        System.out.println("选择排序2："+(endTime-startTime));
    }
    public static void textHeapSort(int[] array){
        //堆排序
        int[] newArray=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();

        HeapSort.heapSort(newArray);

        long endTime=System.currentTimeMillis();
        System.out.println("堆排序："+(endTime-startTime));
    }
    public static void textBubbleSort(int[] array){
        //堆排序
        int[] newArray=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();

        bubbleSort.BubbleSort(newArray);

        long endTime=System.currentTimeMillis();
        System.out.println("冒泡排序："+(endTime-startTime));
    }
    public static void textQuickSort(int[] array){
        //堆排序
        int[] newArray=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();

        QuickSort.quickSork(newArray);

        long endTime=System.currentTimeMillis();
        System.out.println("快速排序："+(endTime-startTime));
    }

    public static void main(String[] args) {
        int[] array=new int[10_0000];

//      inorderArray(array);//有序

      notInorderArray(array);//逆序

//        initArray(array);//乱序

//        int[] newArray=new int[]{10,9,8,7,6,5,4,3,2,1};
//        QuickSort.quickSork(newArray);
//        System.out.println(Arrays.toString(newArray));

        textQuickSort(array);
//        textInsertSort(array);
        textShellSort(array);
        textHeapSort(array);
//        textSelectSort(array);
//        textSelectSort2(array);
//        textBubbleSort(array);




    }
}
